forum

Home / DeveloperSection / Forums / Hot to show info based on what user profile has in android?

Hot to show info based on what user profile has in android?

Anonymous User 1779 18-Nov-2014

I have a ListView and each row contains a different User object.

A User has these different fields:

  • List of things I like
  • List of things I hate
  • List of games I play
  • Description of myself

Now, when I populate the ListView, I want to show different things that each user has filled out. So for example, one row might show 'things I like' filled out, while another might show the 'description of myself'.

I don't want to adjacent rows to be showing the same type of row. All this code will be inserted into my BaseAdapter's getView methood.

What would be the best logic in terms of pseudocode to achieve this?

// Creates arraylist of elements that are complete in profile
List<String> profileElements = new ArrayList<String>();
if (user.getGameOwned() != null && user.getGameOwned().size() > 2) {
    profileElements.add(KEY_GAMES_PLAYED);
}
if (user.getAboutMe() != null && !user.getAboutMe().isEmpty()) {
    profileElements.add(KEY_ABOUT_ME);
}
if (user.getIAm() != null && user.getIAm().length > 2) {
    profileElements.add(KEY_I_AM);
}
if (profileElements.size() > 0) {
    String randomElement = profileElements.get(new Random().nextInt(profileElements.size() - 1));
    if (randomElement.equals(KEY_GAMES_PLAYED)) {
        // do whatever here
    }
    else if (randomElement.equals(KEY_ABOUT_ME)) {
        // do whatever
    }
}


Updated on 19-Nov-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By